/**
 *====================================================
 * 文件名称: BadassetsHandleServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.common.util.RandomUtil;
import com.yuexunit.finance.project.SettingConstants;
import com.yuexunit.finance.project.entity.BadassetsHandleEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;

/**
 * @ClassName: BadassetsHandleServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年09月23日 18:56:17
 */
@Implements(BadassetsHandleService.class)
public class BadassetsHandleServiceImpl implements BadassetsHandleService {

	@Override
	public Long createBadassetsHandle(BadassetsHandleEntity entity) {
		entity.setBadassetsHandleNumber(SettingConstants.PRE_NUMBER_BADASSETS + RandomUtil.generateTimeNumber());
		PersistUtil.insert(entity);
		return entity.getBadassetsHandleId();
	}

	@Override
	public void updateBadassetsHandle(BadassetsHandleEntity entity) {
		BadassetsHandleEntity persist = inquireBadassetsHandle(entity.getBadassetsHandleId());
		BeanUtils.copyProperties(entity, persist);
		PersistUtil.update(persist);
	}

	@Override
	public BadassetsHandleEntity inquireBadassetsHandle(Long badassetsHandleId) {
		return PersistUtil.get(BadassetsHandleEntity.class, badassetsHandleId);
	}

	@Override
	public PageList<BadassetsHandleEntity> inquireBadassetsHandlePageList(Long[] badassetsHandleIds, Long financeId, String financeNumber, Long enterpriseId, String enterpriseName, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(BadassetsHandleEntity.class);
		if (badassetsHandleIds != null && badassetsHandleIds.length > 0) {
			criteria.add(Restrictions.in("badassetsHandleId", badassetsHandleIds));
		}
		if (financeId != null) {
			criteria.add(Restrictions.eq("financeId", financeId));
		}
		if (StringUtils.isNotBlank(financeNumber)) {
			criteria.add(Restrictions.like("financeNumber", "%" + financeNumber + "%"));
		}
		if (enterpriseId != null) {
			criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		if (StringUtils.isNotBlank(enterpriseName)) {
			criteria.add(Restrictions.like("enterpriseName", "%" + enterpriseName + "%"));
		}
		return PersistUtil.get(criteria, page);
	}

}
